package com.sparkseries.common.util.exception;

import com.sparkseries.common.util.domain.Constants;

/**
 * 自定义业务异常处理类
 */
public class BusinessException extends RuntimeException {
    private final Integer code;
    // 错误信息
    private final String message;

    // 默认错误码
    private static final Integer DEFAULT_ERROR_CODE = Constants.DEFAULT_SUCCESS_CODE;

    // 仅包含错误信息
    public BusinessException(String message) {
        super(message);
        this.code = DEFAULT_ERROR_CODE;
        this.message = message;
    }

    // 包含错误码和错误信息
    public BusinessException(Integer code, String message) {
        super(message);
        this.code = code;
        this.message = message;
    }

    // 包含错误信息和原始异常（用于包装底层异常）
    public BusinessException(String message, Throwable cause) {
        super(message, cause);
        this.code = DEFAULT_ERROR_CODE;
        this.message = message;
    }

    public Integer getCode() {
        return code;
    }

    @Override
    public String getMessage() {
        return message;
    }
}
